package com.study

import java.util.Objects

fun main(){
    //`list集合`()
    //`set集合`()
    //`map`()
    //`array`()

//    var test1_= test1("wahaha")
//    println(test1_.name)
}

fun `list集合`(){
    val list1:List<Any> = listOf(1,"我是2",3)
    println(list1)

    val list2= mutableListOf<Int>(1,2,3)
    list2.add(4)
    list2+=5
    list2.removeAt(0)
    list2.removeIf(){
        it==2
    }
    list2[0]
    list2.getOrElse(10){false}
    list2.getOrNull(10)?:false
    println(list2)
    //toMutableList这种操作会断开引用
    var list3=list2.toMutableList()
    list3.add(999)
    print(list2)

    list3.forEach {
        "这是$it"
    }
    list3.forEachIndexed(){
            index,item->
        print("我是下标$index,值为$item")
    }
}

//set是不重复的集合
fun `set集合`(){
    var set1= setOf<String>("a","b","c")
    println(set1)

    var set2= mutableSetOf<String>("A","B","C")
    set2.add("D")
    set2.elementAtOrElse(999){false}
    set2.elementAtOrNull(999)?:false
    println(set2)
}

fun `map`(){
    var map1= mapOf("name" to "wahaha","age" to 24,Pair("haha","yes"))
//    println(map1["name"])
//    println(map1["hahaha"])//null
//    println(map1.getOrElse("666"){false})
//    println(map1.getOrDefault("666",false))
    println(map1)

    var map2= mutableMapOf(Pair("name","wahaha"),"age" to 10)
    map2["sex"]="男"
}

fun `array`(){
    var array1= arrayOf(1,"2",3.0)
    array1.getOrElse(999){false}
    array1.getOrNull(999)?:false
    print(array1)
}

class  test1(var name:String)